package com.test.spring.factory;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/9/26 21:17
 * <p>
 * 静态工厂方法：直接调用某一个类的静态方法就可以返回Bean的实例
 */
public class StaticCarFactory {
    private static Map<String, Car> cars = new HashMap<>();

    static {
        cars.put("audi", new Car("audi", 300000));
        cars.put("ford", new Car("ford", 500000));
    }

    //静态工厂方法
    public static Car getCar(String name) {
        return cars.get(name);
    }
}
